Skip to content

test(routing): add closed-loop starvation simulation for idle evidence - #1262

Merged
Gajesh2007 merged 5 commits into
masterfrom
test/routing-closed-loop-sim
Oct 6, 2026
Merged

Gajesh2007 merged 5 commits into
masterfrom
test/routing-closed-loop-sim

Conversation

@davidtai

@davidtai davidtai commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add a closed-loop routing simulation to coordinator/registry/routingsim and registry tests for the idle-evidence feedback loop in #1238. The change has tests and one documentation paragraph. No production code changes.

This is a draft. Its starvation tests fail on master by design. It must merge after #1243 and #1254. Test failures here notify; they must not block other pull requests.

Only the monotonicity tests are regression tests for #1243. The no-starvation bound and the fleet-median rows assert a proposed policy: from the exploration bound, an explored provider is costed at the fleet median for prefill and decode, and it is selected within the bound plus one request. This policy goes beyond both fix PRs. #1243 keeps an old decode rate for 30 minutes on purpose. #1254 admits an idle provider to the pool and does not promise that it is selected. The maintainers own this policy and its numbers.

Linked issue

Refs #1238, #1243, #1254

How the loop works

The simulation uses only the public registry API, so it lives in routingsim as package tests. No test seam was needed.

  • Virtual clock: testing/synctest. Two simulated hours take less than one second.
  • Arrivals: one deadline-bearing request every 2 s (deadline from TTFTDeadline). Each request takes 39.5 s, so 19 requests are in flight at each arrival. With 20 peers, exactly one peer is idle with current evidence at each arrival.
  • Feedback: the provider that ReserveProviderEx selects sends a running heartbeat, serves, then RemovePending + SetProviderIdle, then a heartbeat through Registry.Heartbeat (the path to reconcileFirstContentMeasurementsLocked). The new noisy sample is blended into the EWMA with the Swift weight 0.3 (provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Accounting.swift:161). A slow "last measurement" in setup is a run of slow samples blended in the same way until the EWMA is within 1 % of the slow rate.
  • Idle providers send unchanged heartbeats every 5 s. Challenges renew every 5 min.
  • Every scenario runs on the legacy EWMA path and on the explicit performance_measurements path (Add provider work measurements and measured warm placement #1233).
  • Providers register without decode_tps or prefill_tps, as the Swift provider does (CoordinatorClientCodec.encodeRegistration).

Assertions:

  • No starvation (proposed policy): every idle, loaded provider is selected within noStarvationBound = 5 min + one request time (39.5 s), counted only while requests arrive. explorationPolicyBound mirrors firstContentEvidenceExplorationAfter from fix(routing): explore idle providers without current first-content evidence #1254; this package cannot read that unexported constant.
  • Concentration: every run reports the busiest provider's share. Only the control asserts a limit (10 %; fair share is 4.5 %).

Results on four trees

Each cell covers both measurement paths (same result on both). "Wait" is the longest idle wait in the 2-hour run.

Test master #1243 #1254 #1243 + #1254 (local merge)
(a) slow last measurement, issue rate 16.2 tok/s FAIL (2 h) FAIL (2 h) pass (2 min) pass (2 min)
(a) slow last measurement, 5 tok/s FAIL (2 h) FAIL (2 h) FAIL (2 h) FAIL (27 min)
(a) slow last prefill measurement, 400 tok/s FAIL (2 h) FAIL (2 h) FAIL (2 h) FAIL (2 h)
(b) fresh provider, no measurement FAIL (1 h 50 min) FAIL FAIL FAIL (1 h 50 min)
(c) idle past the 2-minute evidence window FAIL (1 h 37 min) FAIL pass pass
(d) homogeneous control pass pass pass pass
TestIdleDecodeMeasurementAgeNeverRanksBelowNoMeasurement FAIL pass FAIL pass
TestIdleDecodeMeasurementAgeDoesNotLoseSelection FAIL pass FAIL pass
TestExploredIdleProviderIsCostedAtFleetMedian/no_measurement pass pass pass pass
…/measured_just_past_exploration_bound (6 min, proposed policy) FAIL FAIL FAIL FAIL
…/measured_past_stale_decode_age (31 min) FAIL pass FAIL pass

The local merge had conflicts in first_content_forecast.go (struct fields), first_content_snapshot.go (age initialization) and the routing.md stamp. Both sides were kept. The merge was not pushed.

Findings with both fixes applied

The rows in bold fail with both fixes. They fail against the proposed policy above, not against what #1243 and #1254 promise. The reason is one class: an explored provider is admitted to the pool, but it still ranks outside the 100 ms selection band against an idle peer with current evidence, so it never wins.

  1. Fresh provider (b). The forecast's decode term already uses the fleet median (52 tok/s). The problem is prefill. With no measurement, resolvePrefillTPS (coordinator/registry/scheduler.go, around line 2227) falls back to resolvedPrefillTPS = registration decode × 12 (around line 2467). The Swift provider sends no registration rates, so the registration decode is sqrt(bandwidth) = 20 tok/s and the prefill fallback is 20 × 12 = 240 tok/s. For a 1000-token prompt the expected first content is about 4.3 s against 0.67 s for a measured peer. Even a 50-token prompt is outside the band (378 ms against 194 ms). The fix(routing): explore idle providers without current first-content evidence #1254 test TestFirstContentIdleProviderWithoutEvidenceIsExploredAfterBound sets PrefillTPS = 20000 on the explored provider, so it does not see this.
  2. Slow last decode (a, 5 tok/s). fix(routing): explore idle providers without current first-content evidence #1254 admits the provider at 5 min, but resolveEffectiveTPS keeps the old rate until the fix(routing): expire dated idle decode estimates before ranking #1243 limit of 30 min. The provider waits 27 min after demand starts. At the first pick it is costed at 52.3 tok/s, the fleet median. So "an explored provider is costed at the fleet median" holds only after 30 min, not at the 5-minute exploration bound.
  3. Slow last prefill. resolvePrefillTPS prefers observedPrefillTPS with no age limit. fix(routing): expire dated idle decode estimates before ranking #1243 limits only decode. The provider is never selected in 2 h.

Under the first-content ranking, decode enters the expected forecast as one token time (1000/decode). A slow decode rate matters only when it is far below the median (below about 8.4 tok/s against 52). So at the issue rate, #1254 alone fixes scenario (a), and #1243 alone does not.

Diagrams

Behavior:

flowchart LR
  subgraph Before
    A1[Trace arrival] --> B1[Preflight on a fixed fleet]
    B1 --> C1[Outcome; fleet state never changes]
  end
  subgraph After
    A2[Arrival with deadline] --> B2[ReserveProviderEx]
    B2 --> C2[Provider serves, releases]
    C2 --> D2[Heartbeat with new measurement]
    D2 --> E2[Fleet state for the next arrival]
    E2 --> B2
    F2[Idle heartbeats every 5 s] --> E2
  end
Loading

Code:

flowchart LR
  subgraph Before
    T1[routingsim_test.go] --> Q1[QuickCapacityCheckWithTTFTForRequest]
  end
  subgraph After
    T2[closed_loop_starvation_test.go] --> S2[closed_loop_sim_test.go event loop in synctest]
    S2 --> R2[Registry.ReserveProviderEx]
    S2 --> P2[Provider.RemovePending + SetProviderIdle]
    S2 --> H2[Registry.Heartbeat to reconcileFirstContentMeasurementsLocked]
    T3[idle_evidence_ranking_test.go] --> E3[resolveEffectiveTPS + estimateFirstContent]
    T3 --> R2
  end
Loading

Test plan

  • go test ./registry/... ./registry/routingsim/... on four trees (table above)
  • New tests 20 times with -race -count=20 on this branch and on the local merge (results in a comment)
  • go vet ./registry/..., gofmt -l coordinator/, golangci-lint run ./coordinator/registry/... with v2.1.6: clean
  • make coordinator-test: fails only in the new tests, as expected on master
  • make docs-impact-check BASE=origin/master, make docs-check

Components touched

  • coordinator (Go)
  • provider (Rust, legacy)
  • provider-swift (Swift CLI)
  • console-ui (Next.js)
  • enclave (Swift)
  • infra / CI / release
  • docs

Protocol / interface changes

  • No protocol/interface changes
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/architecture/routing.md, routing simulation harness section.
  • No documentation needed — reason:

Notes for reviewers

🤖 Generated with Claude Code

Refactor Pass

A dedicated refactor subagent reviewed the diff against the AGENTS.md structure, clean-code and refactor rules. Outcome: one test-only cleanup commit, e26fcf9.

  • idle_evidence_ranking_test.go: idleEvidenceFleet.decodeAge is now measurementAge, because the field dates both the prefill and the decode measurement.
  • routingsim/closed_loop_sim_test.go, heartbeat: one branch now sets both the slot state and the heartbeat status. Before, the code checked running > 0 twice.
  • No assertion, seed, schedule or constant changed. As a draft, the PR has tests that fail on purpose against the proposed policy. The same tests fail with the same values before and after this commit: registry seed 1238, case 0, and routingsim waits of 2h0m0s, 1h50m5s and 1h37m4s.

Validation on the final tree: gofmt -l, go vet and golangci-lint v2.1.6 (0 issues) pass. The focused go test runs fail exactly as on the head.

Needs a port before merge. The only text conflict with master c5552d3 is the routing.md stamp line, but the merged tree has two problems:

  • TestCoordinatorTestsAreIsolated rejects all three test files.
  • idle_evidence_ranking_test.go does not compile there. makeSchedulerProvider, firstContentMeasurement, testLogger and testRegisterMessage moved or no longer exist, and the file uses unexported registry internals.

The routingsim files compile in place on master, and there issue_rate, IdleBeyondEvidenceWindow and HomogeneousControl pass.

For the author:

Port to master, 12fe7dc plus 355ff12 (follow-up): the 3 test files moved to coordinator/tests/registry/ and tests/registry/routingsim/, and now use real APIs: Dependencies.Throughput, Dependencies.Measurements with History.Reconcile, ReserveProviderEx decisions, routingsim.DefaultHardwareSpec and TTFTDeadline. No production code changed. The same draft tests fail on purpose with identical numbers, for example 2h0m0s and 1h50m5s waits, and 'costed at 5.0 tok/s, want 52.0'. The comments now use forecast.EvidenceExplorationAfter. Build, vet, lint (0), the layout guard and test-coordinator-tests.py pass.

Extend routingsim with closed-loop tests. The provider that
ReserveProviderEx selects serves the request, releases it, and reports a
changed measurement through Registry.Heartbeat. Idle providers send
unchanged heartbeats. The tests run under testing/synctest, so two
simulated hours take less than one second. Each scenario runs on the
legacy EWMA path and on the explicit measurement path.

Scenarios from #1238: a slow last measurement, a freshly connected
provider, a provider idle longer than the evidence window, and a healthy
control fleet. Every idle, loaded provider must be selected within
5 minutes plus one request time. The control also limits the share of
the busiest provider.

Add registry tests for measurement monotonicity (an old idle decode
measurement must not rank a provider below the same provider with none)
and for the fleet-median cost of an explored provider.

The starvation tests fail on master by design. They are the regression
tests for #1243 and #1254.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@davidtai

Copy link
Copy Markdown
Collaborator Author

Repeat runs with -race. Each result was the same in every run; no test changed between pass and fail.

Tree Tests Runs Result
this branch (master base) TestClosedLoop* 20 control passes 20/20; every starvation subtest fails 20/20
this branch TestIdleDecode*, TestExploredIdle* 20 fails 20/20, except no_measurement passes 20/20
local merge of #1243 and #1254 TestClosedLoop* 19 control, (c) and (a) issue rate pass 19/19; (a) 5 tok/s, (a) slow prefill and (b) fail 19/19
local merge TestIdleDecode*, TestExploredIdle* 20 pass 20/20, except measured_just_past_exploration_bound fails 20/20

The first 20-run batch of routingsim reached the default 10-minute go test timeout under -race (one pass takes about 60 s with the race detector and under 7 s without it). So the remaining runs used -timeout 60m. The merge tree has 19 runs because its first batch stopped after 9.

make coordinator-test on this branch fails only in the new tests (registry and registry/routingsim), as expected on master.

The 5-minute no-starvation bound and the fleet-median cost of an
explored provider go beyond #1243 and #1254. #1254 admits an idle
provider without a selection promise, and #1243 keeps an old decode
rate for 30 minutes on purpose. Say so in the test comments and the
routing doc, and say that the maintainers own the policy.

Name the production constants that the test constants mirror, and say
that the package test must switch to them after the fixes merge.

Use the Swift provider's EWMA weight of 0.3 and blend every sample into
the EWMA, including the slow setup samples. Results on master and on the
local merge of both fixes are unchanged.

Restamp docs/architecture/routing.md with today's date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

davidtai and others added 3 commits October 4, 2026 16:21
…anches

measurementAge dates both the prefill and decode measurements in the idle
evidence tests; the closed-loop heartbeat derives slot state and status once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the routing.md freshness stamp to master's date-only format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rdinator/tests

Port the idle-evidence ranking test and the closed-loop starvation
simulation onto the mirrored test tree, in the external packages:

- tests/registry/idle_evidence_ranking_test.go builds providers with the
  shared scheduler helpers, injects the fleet median through
  Dependencies.Throughput and the measurement history through
  Dependencies.Measurements, and reads each provider's effective decode
  rate and first-content forecast from its ReserveProviderEx decision.
- tests/registry/routingsim/closed_loop_*_test.go register providers
  through Registry.Register with a test-owned registration message
  instead of the package's unexported simRegisterMessage, simModelInfos
  and armSimProvider.
- The starvation bound now uses forecast.EvidenceExplorationAfter (#1254)
  instead of a copied 5-minute constant. The #1243 copy stays, because
  #1243 is not merged.

The tests keep every assertion. They still fail on purpose where the
routing code does not meet the proposed policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacksmith-sh

blacksmith-sh Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Found 3 test failures on Blacksmith runners:

Failures

Test View Logs
TestIntegration_ReferralRewardDistribution View Logs
TestIntegration_SwiftProviderRealRoutingGates View Logs
TestProfile_SingleProviderNonStreaming View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@Gajesh2007
Gajesh2007 marked this pull request as ready for review October 6, 2026 20:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T20:35:50.557443Z 355ff12 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Gajesh2007
Gajesh2007 merged commit 4a106f5 into master Oct 6, 2026
28 of 35 checks passed
@Gajesh2007
Gajesh2007 deleted the test/routing-closed-loop-sim branch October 6, 2026 20:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 355ff12237

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +67 to +69
if p.MaxIdleWait > noStarvationBound {
t.Errorf("seed %d: %s waited %s idle and loaded while requests arrived; bound is %s (selections=%d)",
res.Seed, p.ID, p.MaxIdleWait, noStarvationBound, p.Selections)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not add red policy assertions to the required suite

This unconditional assertion encodes a proposed starvation bound that the accompanying routing documentation explicitly says the production code does not meet, so several new subtests fail by design. Because go test ./coordinator/... discovers this package, every required coordinator test run will remain red until a separate routing change lands; either implement the policy in this commit or keep the experiment opt-in/non-failing until the behavior exists.

AGENTS.md reference: AGENTS.md:L210-L216

Useful? React with 👍 / 👎.

davidtai added a commit that referenced this pull request Oct 7, 2026
Port the rule of #1243 into the performance.Rates layout. An idle,
loaded provider with no local reservations no longer ranks by an observed
decode EWMA whose dated observation is older than
performance.IdleDecodeMaxAge (30 minutes). EffectiveDecode then uses the
fleet median, or the load-scaled registration rate. A reviewed profile
point and the explored fleet median still come first; ProjectedDecode is
unchanged.

The snapshot copies the decode age (decodePerformanceAgeMs) separately
from prefill age, so heartbeats and prefill samples cannot renew it.
fillExplorationRates reads the same field. The ported #1243 tests live in
coordinator/tests/registry/decode_measurement_freshness_test.go, and the
#1262 idle evidence tests now use the production constant.

Co-authored-by: jtrose24 <rosejt24@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

No deployments
benchmarks — 355ff122 Deployed Oct 5, 2026 by davidtai via E2E Benchmarks #2237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants